//
// Created by hugan on 2020/11/20.
//

#include <iostream>
#include "ShellExecuteUtil.h"

int ShellExecuteUtil::open(LPCSTR filePath, LPCSTR runDirectory, LPCSTR param) {
//    std::cout << "filePath=" << filePath << std::endl;
//    std::cout << "runDirectory=" << (runDirectory ? runDirectory : "null") << std::endl;
//    std::cout << "param=" << (param ? param : "null") << std::endl;
    //nShowCmd:每个程序不一定都支持
    ShellExecute(nullptr, "open", filePath, param, runDirectory, SW_SHOWNORMAL);
//    std::cout << "res=" << GetLastError() << std::endl;
    //网上的强转HINSTANCE 不能编译??????????
    return GetLastError();
}

void ShellExecuteUtil::printOpenRes(int res) {
    switch (res) {
        case 0:
            std::cout << "res=success" << std::endl;
            break;
        case ERROR_FILE_NOT_FOUND:
            std::cout << "res=ERROR_FILE_NOT_FOUND" << std::endl;
            break;
        case ERROR_PATH_NOT_FOUND:
            std::cout << "res=ERROR_PATH_NOT_FOUND" << std::endl;
            break;
        case ERROR_BAD_FORMAT:
            std::cout << "res=ERROR_BAD_FORMAT" << std::endl;
            break;
        default:
            std::cout << "res=err:" << res << std::endl;
            break;
    }
}
